package com.tsj.mvp.demo4;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.tsj.mvp.R;

/**
 * 该demo4将attach和detach封装到basePresenter
 * 不足，BasePresenter封装的时候，如果regitsterPresenter继承的时候，传的Loginview又是不对的，所以在demo5中将BasePresenter进行泛化
 * */
public class MainActivity4 extends AppCompatActivity implements LoginView4 {

    private LoginPresenter4 loginPresenter4;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onClickView(View view){
        loginPresenter4 = new LoginPresenter4();
        loginPresenter4.attachView(this);
        loginPresenter4.login("123456","123456");
    }

    @Override
    public void onLoginResult(String result) {
        Toast.makeText(this,result,Toast.LENGTH_LONG).show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(loginPresenter4 != null){
            loginPresenter4.detachView();
        }
    }
}